<template>
  <div class="home">
    <el-container style="height: 100vh">
      <el-header>
        <div>
          <span>“成大通”信息平台</span>
        </div>
        <div>
          <span style="margin-right: 50px;font-size: 14px">{{uinfo.nickname}}</span>
          <el-button type="text" @click="logout" style="color: white">退出</el-button>
        </div>
      </el-header>
      <!--页面主题区域-->
      <el-container>
        <!--侧边栏-->
        <el-aside :width="isCollapse?'64px':'200px'" style="background-color: #333744;">
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <!--侧边栏菜单区域-->
          <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409eff"
            :unique-opened="true"
            :collapse="isCollapse"
            :collapse-transition="false"
            :router="true"
            :default-active="activePath"
          >
            <el-menu-item index="/" >
              <i class="el-icon-pie-chart"></i>
              <span slot="title" >数据中心</span>
            </el-menu-item>
            <el-menu-item index="/myself">
              <i class="el-icon-user-solid"></i>
              <span slot="title">个人中心</span>
            </el-menu-item>
            <el-submenu index="1" :disabled="uinfo.jurisdiction.issh !=='1'">
              <template slot="title">
                <i class="el-icon-folder-checked"></i>
                <span slot="title">审核中心</span>
              </template>
              <el-menu-item index="/contentexamine">内容审核</el-menu-item>
              <el-menu-item index="/comment">评论审核</el-menu-item>
            </el-submenu>
            <el-submenu index="2"  :disabled="uinfo.jurisdiction.isyh !=='1'" >
              <template slot="title">
                <i class="iconfont">&#xe65c;</i>
                <span slot="title">用户管理</span>
              </template>
              <el-menu-item index="/useruser">用户管理</el-menu-item>
              <el-menu-item index="/useradmin" :disabled="uinfo.jurisdiction.issh !=='1' && uinfo.username !== 'admin'" >管理员管理</el-menu-item>
            </el-submenu>
            <el-submenu index="3"  :disabled="uinfo.jurisdiction.isgl !=='1'">
              <template slot="title">
                <i class="el-icon-setting"></i>
                <span slot="title">网站管理中心</span>
              </template>
              <el-menu-item index="/managementlable">标签管理</el-menu-item>
              <el-menu-item index="/carousel">轮播管理</el-menu-item>
            </el-submenu>
            <el-submenu index="4"  :disabled="uinfo.jurisdiction.isfk !=='1'">
              <template slot="title">
                <i class="el-icon-message"></i>
                <span slot="title">反馈中心</span>
              </template>
              <el-menu-item index="/fankui">意见反馈</el-menu-item>
              <el-menu-item index="/jubao">违规举报</el-menu-item>
              <el-menu-item index="/shensu">账号申诉</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!--右侧内容主题-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  name: 'home',
  data () {
    return {
      isCollapse: false,
      // 被激活的链接地址
      activePath: '/'
    }
  },
  computed: {
    ...mapState({
      uinfo: state => state.uinfo
    })
  },
  updated () {
    if (this.$route.name === 'numbering') this.activePath = '/'
    else this.activePath = '/' + this.$route.name
  },
  methods: {
    ...mapActions(['deleteuserinfo']),
    logout () {
      this.deleteuserinfo()
      this.$router.replace('/login')
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }
  },
  created () {
    if (this.$route.name === 'numbering') this.activePath = '/'
    else this.activePath = '/' + this.$route.name
  }
}
</script>

<style scoped>
  .el-header {
    background-color: #373d41;
    color: #333;
    text-align: center;
    line-height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 20px;
  }
  .toggle-button{
    background-color: #4a5064;
    color: white;
    text-align: center;
    font-size: 10px;
    height: 24px;
    line-height: 24px;
    letter-spacing: 0.2rem;
    cursor: pointer;
  }
  .el-main {
    background-color: #eaedf1;
    color: #333;
  }
  .el-menu{
    border-right: none;
  }
</style>
